//
// Created by tang on 22-10-25.
//

#include "frame_buffer.hpp"

namespace GL {
    FrameBuffer::FrameBuffer() : m_handle_(0) {
        GLCallValidation(glGenFramebuffers(1, &m_handle_));
    }
    FrameBuffer::~FrameBuffer() {
        GLCallValidation(glDeleteFramebuffers(1, &m_handle_));
        m_handle_ = 0;
    }
    void FrameBuffer::Bind() const {
        GLCallValidation(glBindFramebuffer(GL_FRAMEBUFFER, m_handle_));
    }

    void FrameBuffer::UnBind() const {
        if (m_handle_ != 0)
            GLCallValidation(glBindFramebuffer(GL_FRAMEBUFFER, 0));
    }

    FrameBufferPtr FrameBuffer::Create() {
        return std::make_unique<FrameBuffer>();
    }
}
